package com.itheima01.day10;

import java.util.ArrayList;

/**
 * @author 刘全
 * @date 2021/7/12
 */
/*
1.创建一个ArrayList集合，用于存储一些字符串：
"abc","def","def","ghi","def","hij","jkol"
	2.遍历集合，统计集合中"def"字符串一共出现了多少个
	3.将集合中的所有"def"字符串删除。打印删除后的集合元素
 */
public class Test02 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("abc");
        list.add("def");
        list.add("def");
        list.add("ghi");
        list.add("def");
        list.add("hij");
        list.add("jkol");
        String s = "def";
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            if(s.equals(list.get(i))){
                count++;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            if(s.equals(list.get(i))){
                list.remove(i);
                i--;
            }
        }
        System.out.println("一共出现了"+count+"个def");
        System.out.println(list);
    }
}
